/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * viewConsultaAtendimento.java
 *
 * Created on 01/06/2012, 16:23:38
 */
package Formularios;

import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Rebecca
 */
public class viewConsultaAtendimento extends javax.swing.JPanel {

    /** Creates new form viewConsultaAtendimento */
    public viewConsultaAtendimento() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        label1 = new java.awt.Label();

        addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                formAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Cliente", "Funcionário", "Serviço", "Data e Hora", "Valor", "Duração em minutos", "Observação", "Situação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setEnabled(false);
        jTable1.setFocusable(false);
        jScrollPane1.setViewportView(jTable1);

        label1.setAlignment(java.awt.Label.CENTER);
        label1.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        label1.setText("Atendimentos Cadastrados");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1370, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(432, 432, 432)
                .addComponent(label1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(697, 697, 697))
            .addGroup(layout.createSequentialGroup()
                .addGap(103, 103, 103)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1080, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 502, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
        // TODO add your handling code here:
        String nomeCliente = null;
        String nomeFuncionario = null;
        String dataHora = null;
        String valor = null;
        String obs = null;
        String duracao = null;
        String sit = null;
        String servico = null;


        try {

            ResultSet rs = SalaoApp.controle.consultaAtendimentos();

            DefaultTableModel model = new DefaultTableModel();

            jTable1.setModel(model);

            model.addColumn("Cliente");
            model.addColumn("Funcionário");
            model.addColumn("Serviço");
            model.addColumn("Data e Hora");
            model.addColumn("Valor");
            model.addColumn("Duração em minutos");
            model.addColumn("Observação");
            model.addColumn("Situação");


            model.setNumRows(0);
            while (rs.next()) {
                dataHora = rs.getString(2) + " - " + rs.getString(3);
                valor = rs.getString(5);
                obs = rs.getString(6);
                duracao = rs.getString(7);
                if (Integer.parseInt(rs.getString(8)) == 1) {
                    sit = "Agendado";
                } else if (Integer.parseInt(rs.getString(8)) == 2) {
                    sit = "Cancelado";
                } else {
                    sit = "Finalizado";
                }

                nomeFuncionario = rs.getString(4);
                nomeCliente = rs.getString(9);

                ResultSet result = SalaoApp.controle.consultaServico();
                while (result.next()) {

                    if (Integer.parseInt(result.getString(1)) == Integer.parseInt(rs.getString(10))) {
                        servico = result.getString(2);
                        break;
                    }
                }

                model.addRow(new Object[]{nomeCliente, nomeFuncionario, servico, dataHora, valor, duracao, obs, sit});



            }

        } catch (Exception exception) {
            exception.printStackTrace();
            System.exit(1);
        }

    }//GEN-LAST:event_formAncestorAdded
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private java.awt.Label label1;
    // End of variables declaration//GEN-END:variables
}
